﻿using System;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
#if !SANDBOX
using PS.Practices.Common.Utilities;
#endif

namespace PS.Practices.Provisioner.Layouts.PS.Practices.Provisioner
{
    public partial class ConfigTest : LayoutsPageBase
    {
        const string Key = "ConfigTest.Key";
        const string Value1 = "Test Value 1";
        const string Value2 = "Test Value 2";
        const string Value3 = "Test Value 3";
        const string Value4 = "Test Value 4";

        protected Label KeyValue1;
        protected TextBox KeyName1;
        protected TextBox ValueName1;

        protected void Page_Load(object sender, EventArgs e)
        {
#if !SANDBOX
            var url = SPContext.Current.Web.Url;
            var storageValue = Config.Get<string>(Key);
            KeyValue1.Text = storageValue;
#endif
        }

        protected void btnRun_Click(object sender, EventArgs e)
        {
#if !SANDBOX
            string keyName = KeyName1.Text;
            string valueName = ValueName1.Text;

            if (!string.IsNullOrEmpty(keyName) && !string.IsNullOrEmpty(valueName))
            {
                Config.Set(SPContext.Current.Web, keyName, valueName, ConfigLevel.Web);
                Config.Set(SPContext.Current.Web, "a0", Value1, ConfigLevel.Web);
                Config.Set(SPContext.Current.Web, "a1", Value2, ConfigLevel.Web);
                Config.Set(SPContext.Current.Web, "a2", Value3, ConfigLevel.Web);
                //Config.Set(SPContext.Current.Web, keyName, valueName, CfgLevel.Site);
            }
#endif
        }
    }
}
